<template>
  <div class="mod-tenant__tenant">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.code" placeholder="全宗号" clearable></el-input>
      </el-form-item>
      <el-form-item prop="tenantCode" label="所属组织机构" class="role-list">
        <el-select v-model="dataForm.tenantCode" placeholder="请选择所属组织机构">
          <el-option v-for="tenant in tenantList" :key="tenant.id" :label="tenant.tenantName" :value="tenant.tenantCode"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <div style="width: 103%; height: 15px; background-color: rgb(240, 242, 245); margin: 0 -21px 15px"></div>
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table stripe v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column label="全宗号" prop="code" sortable="custom" header-align="center" align="center"></el-table-column>
      <el-table-column label="全宗名称" prop="name" header-align="center" align="center"></el-table-column>
      <el-table-column label="所属组织" prop="tenantName" header-align="center" align="center"></el-table-column>
      <el-table-column prop="createDate" label="创建时间" sortable="custom" header-align="center" align="center" width="180"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="padding: 0px 38%" :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <general-archive-add v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></general-archive-add>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import generalArchiveAdd from "./general-archive-add.vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils"; // isEmail, isMobile, isNumber,
import { IObject } from "@/types/interface";
export default defineComponent({
  components: {
    generalArchiveAdd
  },
  setup() {
    const state = reactive({
      getDataListURL: "/archive/info/page",
      getDataListIsPage: true,
      deleteURL: "/archive/info",
      deleteIsBatch: true,
      tenantList: [] as IObject[],
      // exportURL: "/archive/info",
      dataForm: {
        code: "",
        name: "",
        tenantCode:""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  created(){
    this.getOrgInfo()
  },
  methods:{
    getOrgInfo() {
      baseService.get(`/sys/tenant/listAll`).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.tenantList = res.data;
      });
    },
  }
});
</script>
